package com.example.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

@Configuration
public class SSEConfig {
    // 配置SSE专用线程池
    @Bean(name = "sseExecutor")
    public Executor sseExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(20);
        executor.setMaxPoolSize(50);
        executor.setQueueCapacity(1000);
        executor.setThreadNamePrefix("sse-");
        executor.setRejectedExecutionHandler((r, executor1) -> {
            // 当线程池满时的处理策略
            System.out.println("SSE线程池已满，任务被拒绝");
        });
        executor.initialize();
        return executor;
    }
}
